package leesoft.hub.actions;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Map;
import java.util.logging.Logger;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import leesoft.toolbox.PropertyManager;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapHandler;

public class AutoDiagTextAction implements IAction {

	public Map process(SessionContext ctx) {
		String id=ctx.getParameterString("id");
		if(id.equals(""))
			return null;
		// TODO Auto-generated method stub
		String sql="select infotext from tap_cytemplate where id=?";
		String driverName=PropertyManager.getInstance().getValue("datasource.driverClassName");
		String connectionString=PropertyManager.getInstance().getValue("datasource.url");
		String username=PropertyManager.getInstance().getValue("datasource.username");
		String password=PropertyManager.getInstance().getValue("datasource.password");
		
		Connection conn;
		try{
			Class.forName(driverName);
			conn=DriverManager.getConnection(connectionString,username,password);
			QueryRunner run = new QueryRunner();
			Map result=(Map)run.query(conn, sql, new MapHandler(),id);
			HashMap returnMap=new HashMap();
			returnMap.put("text", result.get("infotext"));
			DbUtils.close(conn);  
			return returnMap;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}finally{
			
		}
	}
	public void setRequest(HttpServletRequest request){}
	public void setResponse(HttpServletResponse response){}

}
